package com.chinaunicom.order.trigger.http;

import com.chinaunicom.common.result.JsonResult;
import com.chinaunicom.order.domain.model.entity.CancelOrderEntity;
import com.chinaunicom.order.domain.model.valobj.OrderStatus;
import com.chinaunicom.order.domain.service.OrderAfterService;
import com.chinaunicom.order.trigger.http.vo.CancelOrderVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author guomenghuai
 * @date 2024/1/15
 * @Description
 */
@RestController
@RequestMapping("/afterSale")
public class AfterSaleController {

    @Autowired
    private OrderAfterService orderAfterService;

    /**
     * 用户手动取消订单
     */
    @PostMapping("/cancelOrder")
    public JsonResult<Boolean> cancelOrder(@RequestBody CancelOrderVO cancelOrderRequest) {
        CancelOrderEntity cancelOrder = new CancelOrderEntity();
        cancelOrder.setOrderId(cancelOrderRequest.getOrderId());
        cancelOrder.setUserId(cancelOrderRequest.getUserId());
        cancelOrder.setOrderStatus(OrderStatus.CANCELED.getCode());
        return JsonResult.success(orderAfterService.cancelOrder(cancelOrder));
    }
}
